package com.aerfazhe.stock.service.impl;

import com.aerfazhe.stock.mapper.StockMapper;
import com.aerfazhe.stock.pojo.Order;
import com.aerfazhe.stock.service.StockService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author：wk
 * @Slogan：无论风雨，和自己一决胜负吧
 * @Create：2022/7/21/16:56
 * @Description：库存业务接口实现
 * @Version：1.0
 */
@Service
@Slf4j
public class StockServiceImpl implements StockService {

    @Resource
    private StockMapper stockMapper;

    @Override
//    @Transactional
    @GlobalTransactional
    public Map<String, Object> reductStock(Order order) {
        int i = stockMapper.reductStock(order);
        Map<String,Object> map = new HashMap<>(2);
        if (i == 1) {
            map.put("status",200);
            map.put("msg","库存扣减成功！");
            log.info("库存扣减反馈：{}",map.toString());
            return map;
        }
        map.put("status",500);
        map.put("msg","库存扣减失败！");
        log.info("库存扣减反馈：{}",map.toString());
        return map;
    }

}
